package com.example.designpattern.criteria;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: cph
 * @date: 2022/2/14 18:09
 */
public class CriteriaPatternDemo {
    public static void main(String[] args) {
        List<Person> persons = new ArrayList<>();

        persons.add(new Person("Robert", "Male", "Single"));
        persons.add(new Person("John", "Male", "Married"));
        persons.add(new Person("Laura", "Female", "Married"));
        persons.add(new Person("Diana", "Female", "Single"));
        persons.add(new Person("Mike", "Male", "Single"));
        persons.add(new Person("Bobby", "Male", "Single"));

        Criteria male = new CriteriaMale();
        Criteria female = new CriteriaFemale();
        Criteria single = new CriteriaSingle();
        Criteria singleMale = new AndCriteria(single, male);
        Criteria singleOrFemale = new OrCriteria(single, female);

        System.out.println("male: ");
        printPerson(male.meetCriteria(persons));

        System.out.println("\nfemale: ");
        printPerson(female.meetCriteria(persons));

        System.out.println("\nsingle: ");
        printPerson(single.meetCriteria(persons));

        System.out.println("\nsingleMale: ");
        printPerson(singleMale.meetCriteria(persons));

        System.out.println("\nsingleOrFemale: ");
        printPerson(singleOrFemale.meetCriteria(persons));
    }

    public static void printPerson(List<Person> persons) {
        for (Person p : persons) {
            System.out.println("Person: [name: " + p.getName()
                    + ", gender: " + p.getGender()
                    + ", maritalStatus: " + p.getMaritalStatus()
                    + "]");
        }

    }
}
